home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / editors / eedraw / src / ed / eeredraw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-23  |  10.1 KB  |  308 lines

  1. /*****************************************************************************
  2. *   Program to draw EE diagrams.                         *
  3. *                                         *
  4. * This module redraw/draw all structs.                         *
  5. *                                         *
  6. * Written by:  Gershon Elber            IBM PC Ver 1.0,    Oct. 1989    *
  7. *****************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include "\usr\include\intr_lib.h"
  11. #include "Program.h"
  12. #include "EERedraw.h"
  13. #include "EEModify.h"
  14. #include "EEString.h"
  15. #include "EElayer.h"
  16.  
  17.  
  18.  
  19. static int CursorStartX, CursorStartY;
  20. static DrawGenericStruct *HighLightStruct = NULL;
  21. static DrawPolylineStruct *CrsrPolyline = NULL;
  22. static DrawConnectionStruct *CrsrConnection = NULL;
  23. static IntrCursorShapeStruct Cursor;
  24.  
  25. static void DrawPolylineCursor(int x, int y);
  26. static void DrawConnectionCursor(int x, int y);
  27.  
  28. /*****************************************************************************
  29. * Redraws only the active window which is assumed to be whole visible.         *
  30. *****************************************************************************/
  31. void SetHighLightStruct(DrawGenericStruct *HighLight)
  32. {
  33.     HighLightStruct = HighLight;
  34. }
  35.  
  36. /*****************************************************************************
  37. * Redraws only the active window which is assumed to be whole visible.         *
  38. *****************************************************************************/
  39. void RedrawActiveWindow(void)
  40. {
  41.     IntrWndwPop(EEActiveWindow -> IntrLibWindowID, TRUE, FALSE);
  42. }
  43.  
  44. /*****************************************************************************
  45. * Routine to redraw all windows defined.                     *
  46. *****************************************************************************/
  47. void RedrawAllWindows(void)
  48. {
  49.     IntrWndwRedrawAll();
  50. }
  51.  
  52. /*****************************************************************************
  53. * Routine to redraw list of structs.                         *
  54. * If the list is of DrawPickStruct types then the picked item are drawn.     *
  55. *****************************************************************************/
  56. void RedrawStructList(DrawGenericStruct *Structs, int DrawMode, int Color)
  57. {
  58.     while (Structs) {
  59.     if (Structs -> StructType == DRAW_PICK_ITEM_STRUCT_TYPE)
  60.         RedrawOneStruct(((DrawPickedStruct *) Structs) -> PickedStruct,
  61.                                   DrawMode, Color);
  62.     else
  63.         RedrawOneStruct(Structs, DrawMode, Color);
  64.  
  65.     Structs = Structs -> Pnext;
  66.     }
  67. }
  68.  
  69. /*****************************************************************************
  70. * Routine to redraw list of structs.                         *
  71. *****************************************************************************/
  72. void RedrawOneStruct(DrawGenericStruct *Struct, int DrawMode, int Color)
  73. {
  74.     if (HighLightStruct == Struct)
  75.     Color = EE_HIGHLIGHT_COLOR;
  76.     
  77.  
  78.     switch (Struct -> StructType) {
  79.     case DRAW_POLYLINE_STRUCT_TYPE:
  80.         RedrawPolylineStruct((DrawPolylineStruct *) Struct, DrawMode,
  81.                                     Color);
  82.         break;
  83.     case DRAW_CONNECTION_STRUCT_TYPE:
  84.         RedrawConnectionStruct((DrawConnectionStruct *) Struct,
  85.                                   DrawMode, Color);
  86.         break;
  87.     case DRAW_TEXT_STRUCT_TYPE:
  88.         RedrawTextStruct((DrawTextStruct *) Struct, DrawMode, Color);
  89.         break;
  90.     case DRAW_LIB_ITEM_STRUCT_TYPE:
  91.         DrawLibPart((DrawLibItemStruct *) Struct, DrawMode, Color);
  92.         break;
  93.     }
  94. }
  95.  
  96. /*****************************************************************************
  97. * Routine to redraw polyline struct.                         *
  98. *****************************************************************************/
  99. void RedrawPolylineStruct(DrawPolylineStruct *Struct, int DrawMode, int Color)
  100. {
  101.     int i, CrntColor = GRGetColor();
  102.  
  103.     if(!(ReturnLayerMode(Struct->Layer)&0x03))
  104.     return;
  105.     else if(Color==EE_ERASE_COLOR)
  106.         GRSetColor(EE_ERASE_COLOR);
  107.     else
  108.     GRSetColor(ReturnLayerColor(Struct->Layer)); 
  109.     
  110.  
  111.     GRSetLineStyle(GR_SOLID_LINE, 0, Struct -> Width);
  112.  
  113.     GRSetWriteMode(DrawMode);
  114.  
  115.     GRMoveTo(Struct -> Points[0], Struct -> Points[1]);
  116.     for (i = 1; i < Struct -> NumOfPoints; i++)
  117.     GRLineTo(Struct -> Points[i * 2], Struct -> Points[i * 2 + 1]);
  118.  
  119.     GRSetColor(CrntColor);
  120. }
  121.  
  122. /*****************************************************************************
  123. * Routine to redraw connection struct.                         *
  124. *****************************************************************************/
  125. void RedrawConnectionStruct(DrawConnectionStruct *Struct, int DrawMode,
  126.                                 int Color)
  127. {
  128.     int tmp_color;
  129.     int CrntColor = GRGetColor(), Width = DEFAULT_SNAP_DISTANCE / 2;
  130.  
  131.     if(!(ReturnLayerMode(Struct->Layer)&0x03))
  132.     return;
  133.     else if(Color==EE_ERASE_COLOR)
  134.     GRSetColor(EE_ERASE_COLOR);
  135.     else
  136.     tmp_color=ReturnLayerColor(Struct->Layer); 
  137.     GRSetColor(tmp_color); 
  138.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_NORM_WIDTH);
  139.  
  140.     GRSetWriteMode(DrawMode);
  141.  
  142.     GRSetFillStyle(GR_SOLID_FILL, tmp_color);
  143.  
  144.     GRBar(Struct -> PosX - Width, Struct -> PosY - Width,
  145.       Struct -> PosX + Width, Struct -> PosY + Width);
  146.  
  147.     GRSetColor(CrntColor);
  148. }
  149.  
  150. /*****************************************************************************
  151. * Routine to redraw text struct.                         *
  152. *****************************************************************************/
  153. void RedrawTextStruct(DrawTextStruct *Struct, int DrawMode, int Color)
  154. {
  155.     int CrntColor = GRGetColor();
  156.  
  157.     if(!(ReturnLayerMode(Struct->Layer)&0x03))
  158.     return;
  159.     else if(Color==EE_ERASE_COLOR)
  160.     GRSetColor(EE_ERASE_COLOR);
  161.     else
  162.     GRSetColor(ReturnLayerColor(Struct->Layer)); 
  163.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_NORM_WIDTH);
  164.  
  165.     GRSetWriteMode(DrawMode); 
  166.     
  167.  
  168.     PutTextInfo(Struct -> Orient, Struct -> PosX, Struct -> PosY,
  169.                         Struct -> Scale, Struct -> Text);
  170.  
  171.     GRSetColor(CrntColor);
  172. }
  173.  
  174. /*****************************************************************************
  175. * Routine to place polyline struct. Return TRUE if not aborted.             *
  176. *****************************************************************************/
  177. BooleanType PlacePolylineStruct(DrawPolylineStruct *Struct)
  178. {
  179.     int i, Event, CursorEndX, CursorEndY, Dx, Dy, *Points;
  180.     DrawGenericStruct *Next;
  181.  
  182.     IntrPushCursorType();
  183.     Cursor.CursorType = INTR_CURSOR_CUSTOM;
  184.     Cursor.CursorRoutine = DrawPolylineCursor;
  185.     IntrSetCursorType(&Cursor);
  186.     IntrDrawMessage("Place polyline", EEPopUpForeColor, EEPopUpBackColor);
  187.  
  188.     CrsrPolyline = Struct;
  189.     CursorStartX = GRInvMapX(GRCurrentCursorX);
  190.     CursorStartY = GRInvMapY(GRCurrentCursorY);
  191.  
  192.     /*   Snap the CursorStartX/Y to the real polyline point. As we need to   */
  193.     /* snap to this structure only, make sure its next is NULL.             */
  194.     Next = Struct -> Pnext;
  195.     Struct -> Pnext = NULL;
  196.     SnapPoint2(&CursorStartX, &CursorStartY, FALSE,
  197.                     (DrawGenericStruct *) Struct, NULL);
  198.     Struct -> Pnext = Next;
  199.  
  200.     if ((Event = IntrGetEventWaitSA(&CursorEndX, &CursorEndY)) ==
  201.                             INTR_EVNT_SELECT) {
  202.     CursorEndX = GRInvMapX(CursorEndX);
  203.     CursorEndY = GRInvMapY(CursorEndY);
  204.     Points = Struct -> Points;
  205.     Dx = EE_SNAP(CursorEndX) - EE_SNAP(CursorStartX);
  206.     Dy = EE_SNAP(CursorEndY) - EE_SNAP(CursorStartY);
  207.     for (i = 0; i < Struct -> NumOfPoints; i++) {
  208.         Points[i * 2] += Dx;
  209.         Points[i * 2 + 1] += Dy;
  210.     }
  211.     }
  212.  
  213.     IntrEraseMessage();
  214.     IntrPopCursorType();
  215.  
  216.     return Event != INTR_EVNT_ABORT;
  217. }
  218.  
  219. /*****************************************************************************
  220. * Routine to place connection struct. Return TRUE if not aborted.         *
  221. *****************************************************************************/
  222. BooleanType PlaceConnectionStruct(DrawConnectionStruct *Struct)
  223. {
  224.     int Event, NewX = Struct -> PosX, NewY = Struct -> PosY;
  225.  
  226.     IntrPushCursorType();
  227.     Cursor.CursorType = INTR_CURSOR_CUSTOM;
  228.     Cursor.CursorRoutine = DrawConnectionCursor;
  229.     IntrSetCursorType(&Cursor);
  230.     IntrDrawMessage("Place connection", EEPopUpForeColor, EEPopUpBackColor);
  231.  
  232.     CrsrConnection = Struct;
  233.     if ((Event = IntrGetEventWaitSA(&NewX, &NewY)) == INTR_EVNT_SELECT) {
  234.     Struct -> PosX = EE_SNAP(GRInvMapX(NewX));
  235.     Struct -> PosY = EE_SNAP(GRInvMapY(NewY));
  236.     }
  237.  
  238.     IntrEraseMessage();
  239.     IntrPopCursorType();
  240.  
  241.     return Event != INTR_EVNT_ABORT;
  242. }
  243.  
  244. /*****************************************************************************
  245. * Routine to place text struct. Return TRUE if not aborted.             *
  246. *****************************************************************************/
  247. BooleanType PlaceTextStruct(DrawTextStruct *Struct)
  248. {
  249.     return PlaceString(Struct -> Text, &Struct -> Orient, Struct -> Scale,
  250.                &Struct -> PosX, &Struct -> PosY,
  251.                        INTR_WNDW_PLACE_CENTER);
  252. }
  253.  
  254. /*****************************************************************************
  255. * Routine called by the cursor routine to display current polyline.         *
  256. *****************************************************************************/
  257. static void DrawPolylineCursor(int x, int y)
  258. {
  259.     int i,
  260.         LastColor = GRGetColor();
  261.  
  262.     GRSetColor(EE_HIGHLIGHT_COLOR);
  263.  
  264.     GRSMoveTo(0, y);
  265.     GRSLineTo(GRScreenMaxX, y);
  266.  
  267.     GRSMoveTo(x, 0);
  268.     GRSLineTo(x, GRScreenMaxY);
  269.  
  270.     x = GRInvMapX(x) - CursorStartX;
  271.     y = GRInvMapY(y) - CursorStartY;
  272.  
  273.     GRMoveTo(CrsrPolyline -> Points[0] + x, CrsrPolyline -> Points[1] + y);
  274.     for (i = 1; i < CrsrPolyline -> NumOfPoints; i++)
  275.     GRLineTo(CrsrPolyline -> Points[i * 2] + x,
  276.          CrsrPolyline -> Points[i * 2 + 1] + y);
  277.  
  278.     GRSetColor(LastColor);
  279. }
  280.  
  281. /*****************************************************************************
  282. * Routine called by the cursor routine to display current connection.        *
  283. *****************************************************************************/
  284. static void DrawConnectionCursor(int x, int y)
  285. {
  286.     int Width = DEFAULT_SNAP_DISTANCE / 2,
  287.         LastColor = GRGetColor();
  288.  
  289.     GRSetColor(EE_HIGHLIGHT_COLOR);
  290.  
  291.     GRSMoveTo(0, y);
  292.     GRSLineTo(GRScreenMaxX, y);
  293.  
  294.     GRSMoveTo(x, 0);
  295.     GRSLineTo(x, GRScreenMaxY);
  296.  
  297.     x = GRInvMapX(x);
  298.     y = GRInvMapY(y);
  299.  
  300.     GRMoveTo(x - Width, y - Width);
  301.     GRLineTo(x + Width, y - Width);
  302.     GRLineTo(x + Width, y + Width);
  303.     GRLineTo(x - Width, y + Width);
  304.     GRLineTo(x - Width, y - Width);
  305.  
  306.     GRSetColor(LastColor);
  307. }
  308.